package com.simteek.testspringdata.repository;

import com.simteek.testspringdata.entity.User;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

public interface UserRepository extends MongoRepository<User, String> {

    public List<User> findByFirstNameLike(String firstName);

    public List<User> findByLastNameLike(String lastName);

    public List<User> findByAge(int age);

    public User findBy_id(String _id);


    @Query(value = "{firstName:?0}", fields = "{firstName:1,age:1,_id:0}")
    public List<User> findUsersByParams(String firstName);

    @Query(value = "{firstName:?0}",  count = true)
    public Long getCountByParams(String firstName);

    @Query(value = "{firstName:?0}", exists = true)
    public boolean existsByParams(String firstName);


}
